﻿package com.edzis.reliefglobe{
	import com.flashdynamix.utils.SWFProfiler;
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import org.papervision3d.cameras.CameraType;
	import org.papervision3d.core.geom.renderables.Vertex3D;
	import org.papervision3d.materials.BitmapMaterial;
	import org.papervision3d.materials.MovieMaterial;
	import org.papervision3d.materials.utils.BitmapMaterialTools;
	import org.papervision3d.materials.utils.BumpmapGenerator;
	import org.papervision3d.objects.primitives.Sphere;
	import org.papervision3d.view.BasicView;
	
	public class Main extends Sprite {
		[Embed(source='../../../../lib/reliefglobe_library.swf', symbol='displacemantImage')]
		private var displacemantImage	:Class;
		
		[Embed(source='../../../../lib/reliefglobe_library.swf', symbol='GlobeButtons_design')]
		private var globeButtons	:Class;
		
		private var view:BasicView;
		private var globe:Sphere;
		private var angle:Number;
		
		public function Main():void {
			if (stage) init();
			else addEventListener(Event.ADDED_TO_STAGE, init);
		}
		
		private function init(e:Event = null):void {
			removeEventListener(Event.ADDED_TO_STAGE, init);
			// entry point
			
			SWFProfiler.init(stage, this);
			
			view = new BasicView(0, 0, true, true, CameraType.TARGET);
			addChild(view);
			
			globe = new DisplacementSphere();
		//	globe.rotationX = 90;
			
			view.scene.addChild(globe,"globe");
			view.addEventListener(Event.ENTER_FRAME, updateRotation);
			
			view.startRendering();
		}
		
		private function updateRotation(e:Event):void {
			globe.rotationY += 0.6;
			angle = -(stage.mouseY - stage.stageHeight / 2)/(stage.stageHeight / 2)*15 - 90;
		//	ArthropodDebug.log("angle = " + angle);
			view.camera.orbit(angle, 0);
		}
		
	}
	
}